/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.ui.edge;


public class EStickyFrame extends EFrame{
    public int leftMargin;
    public int rightMargin;
    public int topMargin;
    public int bottomMargin;
    public EStickyFrame(EComponent parent, int width, int height, int leftMargin, int rightMargin, int topMargin, int bottomMargin)
    {
        super(parent, -1, height, width, height);
        this.leftMargin = leftMargin;
        this.rightMargin = rightMargin;
        this.topMargin = topMargin;
        this.bottomMargin = bottomMargin;
        super.setFixed(true);
    }
    @Override
    public int getX()
    {
        if(parent == null)
            return 0;
        if(leftMargin != 0)
            return leftMargin + parent.getX();
        else
            return parent.getX() + parent.getWidth() - rightMargin - getWidth();
    }
    @Override
    public int getY()
    {
        if(parent == null)
            return 0;
        if(topMargin != 0)
            return topMargin + parent.getY();
        else
            return parent.getY() + parent.getHeight() - bottomMargin - getHeight();
    }
    @Override
    public int getWidth()
    {
        if(parent == null)
            return 0;
        if(width == -1)
            return parent.getWidth() - leftMargin - rightMargin;
        else
            return width;
    }
    @Override
    public int getHeight()
    {
        if(parent == null)
            return 0;
        if(height == -1)
            return parent.getHeight() - topMargin -  bottomMargin;
        else
            return height;
    }
}
